#coding=utf-8
import arcpy
path = r'D:\WorkData\20250712四川河流\0821处理'
arcpy.env.workspace = path
arcpy.env.overwriteOutput = True
spatial_ref = arcpy.SpatialReference(4326)

rivs1 = r'D:\WorkData\20250712四川河流\0821处理\rivs1.shp'.decode('utf-8')
rivs2 = r'D:\WorkData\20250712四川河流\0821处理\rivs2.shp'.decode('utf-8')

cs1 = arcpy.da.SearchCursor(rivs1,['SHAPE@','name','flowId','level','rivId','flowRiv'])
i = 0
for row1 in cs1:
    lp = arcpy.PointGeometry(row1[0].lastPoint,spatial_ref)
    flowId = row1[2]
    expression = "rivId = '{}'".format(flowId)
    cs2 = arcpy.da.SearchCursor(rivs2,['SHAPE@','name','level','rivId'],where_clause=expression)
    for row2 in cs2:
        if lp.distanceTo(row2[0]) == 0.0:
            print i,row1[1],row1[4],'汇入',row2[1],row2[3],'lv差',int(row2[2]) - int(row1[3])
        # if row2[0].contains(lp):
        #     print i,row1[1],'汇入',row2[1],'lv差',int(row2[2]) - int(row1[3])
        else:
            print "NG:",row1[1],row1[4],'汇入',row1[5],row1[2],lp.distanceTo(row2[0]),row2[0].lastPoint
    cs2.reset()
    i+=1